//
//  DeepBreathing.swift
//  HIextractLicve
//
//  Created by HIextractLicve on 2024/12/11.
//

import UIKit
import SDCycleScrollView
import ProgressHUD
class DeepBreathing: UIViewController,SDCycleScrollViewDelegate {
    var mindfulness:Set<Int>?
    var eachVioViewHTLC:THLCNOrBUTTOn?
    var mindfulnessPageHTL:THLCNPageControll?
    var journeyHTLC:UIView?
    var suggestion:Set<String>?
    
    var  professionals:Set<CGFloat>?
    
    var exchangeHTLC:[String:Array<Dictionary<String,String>>]?
    
    
    @IBOutlet weak var mineScrovirelwHRTLC: UIScrollView!
    
    @IBOutlet weak var userHeaderHTL: UIImageView!
    
    @IBOutlet weak var usernamhrHTl: UILabel!
    
    @IBOutlet weak var pubtimewHTl: UILabel!
    
    @IBOutlet weak var attitudeButtoneHTl: UIButton!
    

    @IBOutlet weak var gijvenCommHTL: UIButton!
    
    @IBOutlet weak var dyyumTitlewHTl: UILabel!
    
    
    
    
    @IBOutlet weak var oneCommentImg: UIImageView!
    
    
    @IBOutlet weak var ontNamtHTLC: UILabel!
    
    @IBOutlet weak var oneCommentCnontr: UILabel!
    
    
    
    var  passonHtlacData:Dictionary<String,String>
    init(stressdescHTL:Set<Int>,passonHtlacData: Dictionary<String, String>) {
        self.passonHtlacData = passonHtlacData
        super.init(nibName: nil, bundle: nil)
        mindfulness = stressdescHTL
        suggestion = ["decompression"]
        professionals = [12.1]
        exchangeHTLC = ["themtopicHTLC":[["decompression":"098"]]]
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    @objc func bloaaalackSomentoneRemoveHTLC()  {
        
        suggestion = ["decompression"]
        professionals = [12.1]
        exchangeHTLC = ["themtopicHTLC":[["decompression":"098"]]]
        self.navigationController?.popViewController(animated: true)
     }
    
    @IBOutlet weak var moreiconLF: UIButton!
    override func viewDidLoad() {
        super.viewDidLoad()
        if self.navigationController?.navigationBar.isHidden == true {
            journeyHTLC?.alpha = 1
            journeyHTLC?.layer.cornerRadius = 12
        }
        journeyHTLC?.backgroundColor = UIColor(red: 0.06, green: 0.07, blue: 0.07, alpha: 0.01)

        eachVioViewHTLC = THLCNOrBUTTOn.init()
        eachVioViewHTLC?.setTitle("anchors", for: .normal)
        if journeyHTLC != nil {
            journeyHTLC?.addSubview(eachVioViewHTLC ?? THLCNOrBUTTOn.init())
            view.addSubview(journeyHTLC!)
        }

        mindfulnessPageHTL = THLCNPageControll()
        mindfulnessPageHTL?.numberOfPages = 1
        mindfulnessPageHTL?.backgroundColor = UIColor(red: 0.06, green: 0.07, blue: 0.07, alpha: 0.01)
        mindfulnessPageHTL?.tintColor = UIColor(red: 0.06, green: 0.07, blue: 0.07, alpha: 0.01)
        mindfulnessPageHTL?.sizeToFit()

        if journeyHTLC != nil {
            journeyHTLC?.addSubview(mindfulnessPageHTL ?? THLCNPageControll.init())
           
        }

        NotificationCenter.default.addObserver(self, selector: #selector(bloaaalackSomentoneRemoveHTLC), name: NSNotification.Name("htldeleteuser"), object: nil)
      
        
        userHeaderHTL.isUserInteractionEnabled = true
        userHeaderHTL.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(userheaderHTLCTouch)))
        userHeaderHTL.layer.cornerRadius = 20
        userHeaderHTL.layer.masksToBounds = true
        
        oneCommentImg.layer.cornerRadius = 20
        oneCommentImg.layer.masksToBounds = true
        let customized = "1customized0".components(separatedBy: "customized")
        attitudeButtoneHTl.isSelected = (passonHtlacData["HTLCIDIlikeThisDIM"] == customized[0])
        let Timrhg = (passonHtlacData["HTLLiveDYMPiclist"]  ?? "").components(separatedBy: "*")
        // 网络加载图片的轮播器
        if let cycleScrollView = SDCycleScrollView.init(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width - 24.xHTL, height: 420), imageNamesGroup: Timrhg){
            cycleScrollView.delegate = self
            cycleScrollView.pageControlAliment  = SDCycleScrollViewPageContolAlimentCenter
            cycleScrollView.autoScrollTimeInterval = 2
            cycleScrollView.layer.cornerRadius = 20
            cycleScrollView.layer.masksToBounds = true
            
            mineScrovirelwHRTLC.addSubview(cycleScrollView)
            cycleScrollView.snp.makeConstraints({ make in
                make.top.equalToSuperview()
                make.leading.trailing.equalToSuperview().inset(12.xHTL)
                make.height.equalTo(420)
                make.width.equalTo(UIScreen.main.bounds.width - 24.xHTL)
            })
        }

        userHeaderHTL.image = UIImage(named: passonHtlacData["HTLCAvater"]  ?? "")
        usernamhrHTl.text = passonHtlacData["HTLCkiName"]
        pubtimewHTl.text = passonHtlacData["HTLDYMPunoTime"]
       
       dyyumTitlewHTl.text = passonHtlacData["HTLLiveDYMDesc"]
     
        attitudeButtoneHTl.addTarget(self, action: #selector(changeattitudeBuoneHTl), for: .touchUpInside)
        gijvenCommHTL.addTarget(self, action: #selector(giveHTLCcommenrtd), for: .touchUpInside)
      
        if  self.passonHtlacData["oneCommentCnontr"] != nil {
            self.oneCommentImg.image = HTLCAllDealRelaxing.Relaxing.showingHTLimgHead
            self.ontNamtHTLC.text = "Me"
            self.passonHtlacData["oneCommentCnontr"] = self.passonHtlacData["oneCommentCnontr"]
        }
        
        
        
        
        if passonHtlacData["natureImmersion"] == HTLCAllDealRelaxing.Relaxing.signinUserDataHTL["natureImmersion"] {
           
            usernamhrHTl.text = "Me"
            gijvenCommHTL.isHidden = true
            attitudeButtoneHTl.isHidden = true
            moreiconLF.isHidden = true
        }
        
        
    }
    
    @objc func userheaderHTLCTouch()  {
        var huihuo = 43
        huihuo += 1
        var pagenorHTLC = 23
        pagenorHTLC -= 2
        let community:Set<Int> = [huihuo,pagenorHTLC]
        let dymusercenterVC = NnnerCalmtrn.init(stressdescHTL: community, passonHtlacData: passonHtlacData)
        
        self.navigationController?.pushViewController(dymusercenterVC, animated: true)
    }
    
    
    
    
    @IBAction func morecTouchHTLC(_ sender: Any) {
        suggestion = ["decompression"]
        professionals = [12.1]
        exchangeHTLC = ["themtopicHTLC":[["decompression":"098"]]]
        self.navigationController?.pushViewController(UntentionSetting(), animated: true)
    }
    @objc func changeattitudeBuoneHTl()  {
        suggestion = ["decompression"]
        professionals = [12.1]
        exchangeHTLC = ["themtopicHTLC":[["decompression":"098"]]]
        ProgressHUD.animate()
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.0, execute: DispatchWorkItem(block: {
            
          
            ProgressHUD.dismiss()
            self.attitudeButtoneHTl.isSelected = !self.attitudeButtoneHTl.isSelected
            var huihuo = 43
            huihuo += 1
            var pagenorHTLC = 23
            pagenorHTLC -= 2
            let community:Set<Int> = [huihuo,pagenorHTLC]
            
            HTLCAllDealRelaxing.Relaxing.revertMyAitudeTHTLCoDynm(stressdescHTL: community, whoseDYMHTL: self.passonHtlacData, islikejHTL: self.attitudeButtoneHTl.isSelected)
          
          
            return
        }))
    }
    
    
    @objc func giveHTLCcommenrtd() {
        
        let LaertController = UIAlertController(title:HTLROOOMMeasg.BinrwetioBase64("Q29tbWVudA=="),  message: "Enter content in the input box", preferredStyle: .alert)
        LaertController.addTextField { (textField) in
            textField.placeholder = HTLROOOMMeasg.BinrwetioBase64("U2F5IHNvbXRoaW5nLi4uLg==")
        }
        suggestion = ["decompression"]
        professionals = [12.1]
        exchangeHTLC = ["themtopicHTLC":[["decompression":"098"]]]
      
        
       
        let sureactiond = UIAlertAction(title: HTLROOOMMeasg.BinrwetioBase64("U3VyZQ=="), style: .default) { (_) in
            if let text = LaertController.textFields?.first?.text {
                ProgressHUD.animate()
                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1, execute: DispatchWorkItem(block: {
                    
                    var huihuo = 43
                    huihuo += 1
                    var pagenorHTLC = 23
                    pagenorHTLC -= 2
                    let community:Set<Int> = [huihuo,pagenorHTLC]
                    if  self.passonHtlacData["oneCommentCnontr"] == nil {
                        ProgressHUD.dismiss()
                        self.oneCommentImg.image = HTLCAllDealRelaxing.Relaxing.showingHTLimgHead
                        self.ontNamtHTLC.text = "Me"
                        self.oneCommentCnontr.text = text
                        
                        self.passonHtlacData["oneCommentCnontr"] = text
                        
                        HTLCAllDealRelaxing.Relaxing.insertOntComment(stressdescHTL: community, whoseDYMHTL:  self.passonHtlacData, contentHTL: text)
                    }else{
                       
                            ProgressHUD.succeed(HTLROOOMMeasg.BinrwetioBase64("WW91ciBzdWJtaXRpbmcgY29tbWVudCBpcyBjdXJyZW50bHkgdW5kZXIgcmV2aWV3ISE="), delay: 2.5)
                        
                        
                    }
                  
                    
                }))
            }
        }
        let cangelAction = UIAlertAction(title: HTLROOOMMeasg.BinrwetioBase64("Q2FuY2Vs"), style: .cancel, handler: nil)
                
       
        LaertController.addAction(cangelAction)
        
        LaertController.addAction(sureactiond)
        
        // 显示弹窗
        present(LaertController, animated: true, completion: nil)
    }

    @IBAction func backNowerHTLC(_ sender: Any) {
      
            self.navigationController?.popViewController(animated: true)
        
        
    }
}
